# -*- coding: utf8 -*-
# @author='dapeng',
# @version='1.0.0'
import os
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest
import configparser,json

cf = configparser.ConfigParser()
cf.read("D:/Program Files/pycharm/wechat-robot/configuration/config.ini")  # 读取配置文件，如果写文件的绝对路径，就可以不用os模块

appkey = cf.get("Aliyun", "appkey")
appsecret = cf.get("Aliyun", "appsecret")



# 创建AcsClient实例
client = AcsClient(
    appkey,
    appsecret,
    "cn-shanghai"
);


#获取token
def gettoken():

    # 创建request，并设置参数。
    request = CommonRequest()
    request.set_method('POST')
    request.set_domain('nls-meta.cn-shanghai.aliyuncs.com')
    request.set_version('2019-02-28')
    request.set_action_name('CreateToken')
    response = client.do_action_with_exception(request)
    jsons = json.loads(str(response,'utf-8'))
    return jsons.get('Token').get('Id')
